//
//  DoctorBarCodeViewController.m
//  LPTClient
//
//  Created by apple on 2018/12/5.
//  Copyright © 2018 zhaodd. All rights reserved.
//

#import "DoctorBarCodeViewController.h"
#import "MMProgressHUD.h"

@interface DoctorBarCodeViewController ()

@property (nonatomic, weak) IBOutlet UIView *shareView;

@property (nonatomic, weak) IBOutlet UIImageView *iconImageView;
@property (nonatomic, weak) IBOutlet UIImageView *barCodeImageView;
@property (nonatomic, weak) IBOutlet UILabel *nickNameLab;
@property (nonatomic, weak) IBOutlet UILabel *descLab;


@end

@implementation DoctorBarCodeViewController


+ (instancetype)instance
{
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"DocBarCode" bundle:nil];
    DoctorBarCodeViewController *vc = [storyBoard instantiateInitialViewController];
    return vc;
}


- (void)viewDidLoad {
    [super viewDidLoad];

    
    UserInfo *userInfo = [LTPCacheManager shareInstance].getUserInfoModel.doctor;
    
    NSString *url = userInfo.credential.figure_file.url;
    NSString *barcode_url = userInfo.qrcode.url;

    [self.iconImageView setImageWithURL:[NSURL URLWithString:IMG_URL(url)] placeholder:[UIImage imageNamed:@"my_nav_portrait"]];
    self.nickNameLab.text = userInfo.credential.name;
    
    [self.barCodeImageView setImageWithURL:[NSURL URLWithString:IMG_URL(barcode_url)] placeholder:nil];
    
    self.descLab.text = @"微信扫描上方二维码\n关注【喜郎中】公众号\n随时向我问诊";
}


- (IBAction)shareAction:(id)sender
{
    
    UIImage *image =  [self.shareView snapshotImage];
    
    // 设置分享内容
    //NSString *text = @"";
    //UIImage *image = [UIImage imageNamed:@"news_icon_Interrogation"];
    //NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];
    NSArray *activityItems = @[image];
    
    UIActivityViewController *activityViewController =    [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [self presentViewController:activityViewController animated:YES completion:nil];
    
    // 选中活动列表类型
    [activityViewController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
        //NSLog(@"act type %@",activityType);
        [MMProgressHUD show];
        if (completed) {
            [MMProgressHUD dismissWithSuccess:@"分享成功"];
        }else {
            [MMProgressHUD dismissWithSuccess:@"分享取消"];
        }
    }];

    
}


@end
